cmake_minimum_required(VERSION 3.18.0)
project(h2o_app)
find_library(CRYPTO_LIB crypto REQUIRED)
find_library(H2O_LIB h2o-evloop REQUIRED)
find_library(MUSTACHE_C_LIB mustache_c REQUIRED)
find_library(NUMA_LIB numa REQUIRED)
find_library(PQ_LIB pq REQUIRED)
find_library(SSL_LIB ssl REQUIRED)
find_library(YAJL_LIB yajl REQUIRED)
find_library(Z_LIB z REQUIRED)
find_path(H2O_INCLUDE h2o.h REQUIRED)
find_path(MUSTACHE_C_INCLUDE mustache.h REQUIRED)
find_path(NUMA_INCLUDE numaif.h REQUIRED)
find_path(OPENSSL_INCLUDE openssl/ssl.h REQUIRED)
find_path(PQ_INCLUDE postgresql/libpq-fe.h REQUIRED)
find_path(YAJL_INCLUDE yajl/yajl_gen.h REQUIRED)
include_directories(src ${H2O_INCLUDE} ${MUSTACHE_C_INCLUDE} ${NUMA_INCLUDE} ${OPENSSL_INCLUDE})
include_directories(${PQ_INCLUDE} ${YAJL_INCLUDE})
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
add_compile_definitions(H2O_USE_LIBUV=0)
set(COMMON_OPTIONS -flto -pthread)
add_compile_options(-pedantic -Wall -Wextra ${COMMON_OPTIONS})
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_FORTIFY_SOURCE=2")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -O3")
file(GLOB_RECURSE SOURCES "src/*.c")
add_executable(${PROJECT_NAME} ${SOURCES})
target_link_libraries(${PROJECT_NAME} ${COMMON_OPTIONS})
target_link_libraries(${PROJECT_NAME} ${H2O_LIB} ${MUSTACHE_C_LIB} ${NUMA_LIB} ${PQ_LIB} ${SSL_LIB})
target_link_libraries(${PROJECT_NAME} ${CRYPTO_LIB} ${YAJL_LIB} ${Z_LIB})
install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION bin)
file(GLOB TEMPLATES "template/*")
install(FILES ${TEMPLATES} DESTINATION share/${PROJECT_NAME}/template)
